package model

import (
	"auth/model/entity"
)

type MenuCreateRequest struct {
	ParentId *int64 `json:"parent_id"  binding:"required"`

	Path string `json:"path" binding:"required"`

	Name string `json:"name" binding:"required"`

	MenuLevel int `json:"menu_level"`

	Hidden int `json:"hidden"`

	Component string `json:"component" binding:"required"`

	Sort int `json:"sort"`

	ActiveName string `json:"active_name"`

	KeepAlive int `json:"keep_alive"`

	DefaultMenu int `json:"default_menu"`

	Title string `json:"title" binding:"required"`

	Icon string `json:"icon"`

	CloseTab int `json:"close_tab"`

	Permission string `json:"permission"`
}

type MenuUpdateRequest struct {
	ID int64 `json:"id" binding:"required"`

	Path string `json:"path" binding:"required"`

	Name string `json:"name" binding:"required"`

	MenuLevel int `json:"menu_level"`

	Hidden int `json:"hidden"`

	Component string `json:"component" binding:"required"`

	Sort int `json:"sort"`

	ActiveName string `json:"active_name"`

	KeepAlive int `json:"keep_alive"`

	DefaultMenu int `json:"default_menu"`

	Title string `json:"title"  binding:"required"`

	Icon string `json:"icon"`

	CloseTab int `json:"close_tab"`

	ParentId *int64 `json:"parent_id"  binding:"required"`

	Permission string `json:"permission"`
}

type MenuListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	ID int64 `json:"id"`

	ParentId int64 `json:"parent_id"`

	Path string `json:"path"`

	Name string `json:"name" `
}

type AddMenuAuthorityInfoRequest struct {
	Menus       []*MenuInfo `json:"menus"`
	AuthorityId int64       `json:"authorityId"` // 角色ID
}

type GetMenuAuthorityRequest struct {
	AuthorityId int64 `json:"authorityId" binding:"required"` // 角色ID
}

type GetMenuAuthorityResponse struct {
	Data []*MenuInfo `json:"list"`
}

type MenuListResponse struct {
	Total int         `json:"total"`
	Data  []*MenuInfo `json:"list"`
}

type SysBaseMenusResponse struct {
	Data []*MenuInfo `json:"list"`
}

type GetMenuListResponse struct {
	Data []*MenuInfo `json:"list"`
}

type MenuInfo struct {
	ID int64 `json:"id"`

	MenuLevel int `json:"-"`

	ParentId int64 `json:"parent_id"`

	Path string `json:"path"`

	Name string `json:"name"`

	Hidden int `json:"hidden"`

	Component string `json:"component"`

	Sort int `json:"sort"`

	ActiveName string `json:"active_name"`

	KeepAlive int `json:"keep_alive"`

	DefaultMenu int `json:"default_menu"`

	Title string `json:"title"`

	Icon string `json:"icon"`

	CloseTab int `json:"close_tab"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`

	Children []*MenuInfo `json:"children" gorm:"-"`

	Permission string `json:"permission"`
}

type MenuDeleteRequest struct {
	ID int64 `json:"id"  validate:"required"`
}

func MenusEntityToDto(menus []*entity.Menu) []*MenuInfo {
	out := make([]*MenuInfo, 0, len(menus))
	for _, c := range menus {
		out = append(out, MenuEntityToDto(c))
	}
	return out
}

func MenusDtoToEntity(menuInfo []*MenuInfo) []entity.Menu {
	out := make([]entity.Menu, 0, len(menuInfo))
	for _, c := range menuInfo {
		out = append(out, MenuDtoToEntity(c))
	}
	return out
}

func MenuEntityToDto(e *entity.Menu) *MenuInfo {
	return &MenuInfo{

		ID: e.ID,

		MenuLevel: e.MenuLevel,

		ParentId: e.ParentId,

		Path: e.Path,

		Name: e.Name,

		Hidden: e.Hidden,

		Component: e.Component,

		Sort: e.Sort,

		ActiveName: e.ActiveName,

		KeepAlive: e.KeepAlive,

		DefaultMenu: e.DefaultMenu,

		Title: e.Title,

		Icon: e.Icon,

		CloseTab: e.CloseTab,

		CreatedAt: e.CreatedAt,

		UpdatedAt:  e.UpdatedAt,
		Permission: e.Permission,
	}
}

func MenuDtoToEntity(e *MenuInfo) entity.Menu {
	return entity.Menu{

		ID: e.ID,

		MenuLevel: e.MenuLevel,

		ParentId: e.ParentId,

		Path: e.Path,

		Name: e.Name,

		Hidden: e.Hidden,

		Component: e.Component,

		Sort: e.Sort,

		ActiveName: e.ActiveName,

		KeepAlive: e.KeepAlive,

		DefaultMenu: e.DefaultMenu,

		Title: e.Title,

		Icon: e.Icon,

		CloseTab: e.CloseTab,

		CreatedAt: e.CreatedAt,

		UpdatedAt:  e.UpdatedAt,
		Permission: e.Permission,
	}
}
